function [] = mult_unsigned_tb()
    a = 1;
    b = 5;
    c = a*b;
    n = 4;
    A = to_bin(a,n);
    B = to_bin(b,n);
    C = to_bin(c,n);
    X = mult_unsigned(A,B);
    assert(a,b,c,A,B,C,X(n:end));

    a = 5;
    b = 1;
    c = a*b;
    n = 4;
    A = to_bin(a,n);
    B = to_bin(b,n);
    C = to_bin(c,n);
    X = mult_unsigned(A,B);
    assert(a,b,c,A,B,C,X(n:end));

    a = 5;
    b = 5;
    c = a*b;
    n = 5;
    A = to_bin(a,n);
    B = to_bin(b,n);
    C = to_bin(c,n);
    X = mult_unsigned(A,B);
    assert(a,b,c,A,B,C,X(n:end));

    a = 245;
    b = 3;
    c = a*b;
    n = 10;
    A = to_bin(a,n);
    B = to_bin(b,n);
    C = to_bin(c,n);
    X = mult_unsigned(A,B);
    assert(a,b,c,A,B,C,X(n:end));
end

function [] = assert(a,b,c,A,B,C,X)
    if(C == X)
        fprintf('\tYes: %d*%d=%d => %s*%s=%s\n',a,b,c,mat2str(A),mat2str(B),mat2str(C));
    else
        fprintf('\tNo : %d*%d=%d => %s*%s=%s, correct is: %s\n',a,b,c,mat2str(A),mat2str(B),mat2str(C),mat2str(X));
    end
end

function B = to_bin(d,n)
    B = dec2bin(abs(d))-48;
    if(d < 0)
        B = negate(B);
        T = ones(1,n);
    else
        T = zeros(1,n);
    end
    len = length(B);
    T(n-len+1:n) = B;
    B = T;
end

function X = negate(X)
    X = not(X);
    X(end) = X(end)+1;
    C = 1;
    while(sum(C)>0)
        C = X==2;
        C_LS = [C(2:end) 0];
        X(X==2) = 0;
        X = X + C_LS;
    end
end